package cn.bone.mqtt.demo03;

import cn.bone.utils.HttpUtil;
import okhttp3.Credentials;
import org.apache.commons.codec.binary.Base64;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by MD-01 on 2017/4/25.
 */
public class HttpPush {

    public static void main(String[] args){

        String url = "http://172.16.252.234:8083/mqtt/publish";
        String basic = Credentials.basic(
                "admin",
                "public",
                Charset.forName("UTF-8"));
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Authorization", basic);

        List<HttpUtil.FormBean> beanList = new ArrayList<>();
        beanList.add(new HttpUtil.FormBean("clientId","server-push"));
        beanList.add(new HttpUtil.FormBean("qos","2"));
        beanList.add(new HttpUtil.FormBean("retain","1"));
        beanList.add(new HttpUtil.FormBean("topic","topic/client-02"));
        beanList.add(new HttpUtil.FormBean("message","今天天气不错哟"));

        String result = HttpUtil.post(url, headers, beanList);
        System.out.println(result);
    }


}
